<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="format-detection" content="telephone=no">
        <title>物品详情</title>

        <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>

        <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> 
        <link rel="stylesheet" href="./Public/awesome/font-awesome.min.css">
        <link rel="stylesheet" href="./Public/css/index.css">
        <link rel="stylesheet" href="./Public/js/PhotoSwipe/photoswipe.css">
        <link rel="stylesheet" href="./Public/js/Scrollbar/jquery.mCustomScrollbar.css">
        <!-- <link rel="stylesheet" href="./Public/css/lightbox.css"> -->
        <script src="./Public/ga.js"></script>
        <script src="./Public/timeFormat.js"></script>

        <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script> 
        <script src="./Public/js/PhotoSwipe/klass.min.js"></script>
        <script src="./Public/js/PhotoSwipe/code.photoswipe.jquery-3.0.5.min.js"></script>
        <!-- <script src="./Public/js/lightbox.js"></script>
        <script src="./Public/js/imagelightbox.min.js"></script> -->
        <script src="./Public/js/Scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
        <script src="./Public/js/index.js"></script> 
        <script src="https://cdn1.lncld.net/static/js/av-min-1.5.0.js"></script>
        <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
        <script type="text/javascript">
            var img = '{$img}';
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: 'wxf20953cc201449dd', // 必填，公众号的唯一标识
                timestamp: '{$Think.session.timestamp}', // 必填，生成签名的时间戳
                nonceStr: '{$Think.session.nonceStr}', // 必填，生成签名的随机串
                signature: '{$signature}',// 必填，签名，见附录1
                jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
            });
        
            wx.ready(function(){
                wx.onMenuShareTimeline({
                    title: '{$name}', // 分享标题
                    link: 'http://www.kmic168.com/?m=web&a=goodsPage&gid={$gid}', // 分享链接,将当前登录用户转为puid,以便于发展下线
                    desc: '价格：￥{$price} (包邮)',
                    imgUrl: img, // 分享图标
                    success: function () { 
                        // 用户确认分享后执行的回调函数
                    },
                    cancel: function () { 
                        // 用户取消分享后执行的回调函数
                    },
                    trigger: function (res) {
    
                    },
                    fail: function (res) {
                    }
                });
                
                wx.onMenuShareAppMessage({
                    title: '{$name}', // 分享标题
                    link: 'http://www.kmic168.com/?m=web&a=goodsPage&gid={$gid}', // 分享链接,将当前登录用户转为puid,以便于发展下线
                    desc: '价格：￥{$price} (包邮)',
                    imgUrl: img, // 分享图标
                    type: 'link', // 分享类型,music、video或link，不填默认为link
                    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                    success: function () { 
                        // 用户确认分享后执行的回调函数
                    },
                    cancel: function () { 
                        // 用户取消分享后执行的回调函数
                    }
                });
            });
        </script>

    </head>
        
    <body><input type="hidden" name="openid" value="{$Think.get.openid}" />

        <!-- header -->
        <header class="detail-header">
            <div class="back">
            </div>
            <div class="header-title">
                <p>详情</p>
            </div>     
        </header>

        <!-- 弹窗 -->
        <div class="f_windown1">
            <div class="bg"></div>
            <div class="ui-scroller">
                <div id="f_close1"><img src="./Public/Kmic/close.png" width="30"/></div>
                <div class="f_close_line"></div>
                <div class="windown-info">
                    <p>请输入您的留言</p>
                    <div class="message" contenteditable></div>
                    <p class="tips">请不要发垃圾广告与反动言论,用户举报将永久封号.</p>
                    <a class="send-message" href="javascript:;">发送</a>
                </div>
            </div>
        </div> 
        
        <!-- section -->
        <section class="artist-detail">

            <div class="col-xs-12 detail-item info-title">
                <img class="img-circle head-img" src="">
                <div class="detail-title-content">
                    <span class="artist-name">{$name}</span>
                    <span class="artist-id">{$city} | 麦麦号：{$user_id}</span>
                </div>
            </div>
            
            <div class="col-xs-12 detail-item">
                <div class="item">
                    宝贝图片
                </div>
                <div id="artist_img">
                    <ul id="Gallery" class="gallery">
                        
                    </ul>
                </div>
            </div>

            <div class="col-xs-12 detail-item detail-item-activity">
                <p class="title">详细信息</p>
                <div class="item-list">
                    <h4>名称:</h4><span class="name"></span>
                </div>
                <div class="item-list">
                    <h4>尺码:</h4><span class="size"></span>
                </div>
                <div class="item-list">
                    <h4>新旧程度:</h4><span class="new"></span>
                </div>
                <div class="item-list">
                    <h4>材料:</h4><span class="material"></span>
                </div>
                <div class="item-list">
                    <h4>三围:</h4><span class="measurements"></span>
                </div>
                <div class="item-list">
                    <h4>描述:</h4><span class="original_desc"></span>
                </div>

            </div>

        </section>

        <div class="detail-item-enroll artist-contact">
            <div class="price">
                
            </div>
            <div class="signup">

            </div>
        </div>
    

    <script>

        $('.back').click(function() {
            var mine = window.location.href.indexOf('mine');
            if (mine != -1) {
                window.location.href = '?m=web&c=index&a=mineExchange&openid={$Think.get.openid}'
            } else {
                window.location.href = '/?m=web&c=index&a=goods&openid={$Think.get.openid}&back'
            }
        });

        var openid = "{$Think.session.openid}";
        var picNum = 0;
        var gid = '{$gid}';

        $.ajax({
            type: 'GET',
            url: "?m=Web&a=goodsDetails",
            data: {'gid': gid},
            complete:function(result){
            //console.log('complete:function');
            },
            success: function(result){
                console.log(result);

                $('.info-title img').attr('src', result.userDetail.headimgurl);
                $('.artist-name').html(result.userDetail.name);
                if (result.userDetail.city) {
                    $('.artist-id').html(result.userDetail.city + ' | ' + result.user_id);
                } else {
                    $('.artist-id').html(result.user_id);
                }
                var time = getDateDiff(result.modify_time);
                $('.modify-time').html(time);

                if (result.exchange_pic.length > 0) {
                    var picId = "";
                    $.each(result.exchange_pic, function(i,val){

                        //形象展示
                        $('#Gallery').append('<li><a href="'+ val.value + '"  data-imagelightbox="e" class="picItem">\n\
                            <img class=\"art-img lazy_img\" src="./Public/img/img_cover.png" style="background: url(\''+ val.value + '\') no-repeat center/cover;" alt="照片展示"></a></li>');   
                        
                    });

                    (function(window, $, PhotoSwipe){
                        $(document).ready(function(){
                            var options = {};
                            $("#Gallery a").photoSwipe(options);
                        });
                    }(window, window.jQuery, window.Code.PhotoSwipe));
                    
                    $.mCustomScrollbar.defaults.theme="light-2"; 
                    
                    $("#Gallery").mCustomScrollbar({
                        axis:"x",
                        advanced:{autoExpandHorizontalScroll:true}
                    });

                } else {
                    $('.goods-img').remove();
                }

                var size = '';
                if (result.size == 0) {
                    size = '均码';
                } else if (result.size == 1) {
                    size = 'S码';
                } else if (result.size == 2) {
                    size = 'M码';
                } else if (result.size == 3) {
                    size = 'L码';
                }

                var g_new = '';
                if (result.new == 10) {
                    g_new = '全新';
                } else if (result.new == 1) {
                    g_new = '偏旧';
                } else if (result.new == 8) {
                    g_new = '8成新';
                } else if (result.new == 8.5) {
                    g_new = '8.5成新';
                } else if (result.new == 9) {
                    g_new = '9成新';
                } else if (result.new == 9.5) {
                    g_new = '9.5成新';
                } else {
                    g_new = 0;
                }

                if (g_new != 0) {
                    $('.new').html(g_new);    
                } else {
                    $('.new').parent().remove();
                } 

                $('.size').html(size);

                $('.name').html(result.title);

                infoToggle('material');
                infoToggle('measurements');
                infoToggle('original_desc');

                function infoToggle(element) {
                   if (result[element] != '') {
                        $('.'+element).html(result[element]);    
                    } else {
                        $('.'+element).parent().remove();
                    } 
                }

                
                
                var price_h = '';
                var price = '';
                var priceText = '';
                if (result.price_h != null) {
                    if (result.price_h.length > 1) {
                        price_h = "-"+result.price_h;
                    }
                }
                if (result.price  == -1 || result.price == 0) {
                    price = '自报价格';
                    priceText = '<p><span class="enroll-money">自报</span></p>';
                }else {
                    price = result.price + price_h;
                    priceText += '<p><span class="enroll-sign">{$Think.lang.L_CURRENCY_SIGN}</span><span class="enroll-money">'+  price + '</span>'
                }                
                $('.price').append(priceText);

                if (result.fromuid != result.uid) {
                    $('.signup').append('<button type="button" class="email_button" onclick="more(\''+result.title+'\',\''+result.id+'\',\''+result.uid+'\',\''+result.fromuid+'\');">留言</button>');
                }
            }
        });

        

        function html_decode(str) {   
            var s = "";   
            if (str.length == 0) return "";   
            s = str.replace(/&gt;/g, "&");   
            s = s.replace(/&lt;/g, "<");   
            s = s.replace(/&gt;/g, ">");   
            s = s.replace(/&nbsp;/g, " ");   
            s = s.replace(/&#39;/g, "\'");   
            s = s.replace(/&quot;/g, "\"");   
            s = s.replace(/<br>/g, "\n");   
            return s;   
        }   
    </script>
    
    </body>
</html>
